from pyecharts.charts import Map
import pyecharts.options as opts
import json

f = open('/Users/yanfeixingsan/Documents/进阶之路/python/test/可视化案例数据/地图数据/疫情.txt', 'r', encoding="UTF-8")
data_json = f.read()
f.close()
data_dict = json.loads(data_json)

province_data_list = data_dict['areaTree'][0]['children']
shanxi_data_list = []
num = 0
for item in province_data_list:
    if item['name'] == '山西':
        while num < len(item['children']):
            shanxi_data_list.append([item['children'][num]['name'] + '市', 22])
            num += 1

map = Map()
map.add("山西地图", shanxi_data_list, "山西")
map.set_global_opts(
    title_opts=opts.TitleOpts(is_show=True, title='山西地图')
)

map.render('山西地图.html')
